import {Metadata_Key} from "../../constants";

/** PostConstruct装饰器配置 */
export interface PostConstructOption {
}

/** PostConstruct装饰器定义 */
export interface PostConstructDecorator {
  (option?: PostConstructOption): MethodDecorator;
}

/** PostConstruct装饰器 */
const PostConstruct = <PostConstructDecorator>function (option?: PostConstructOption): MethodDecorator {
  // PostConstruct装饰器配置默认值
  const defaultOption: Partial<PostConstructOption> = {};
  // PostConstruct装饰器配置
  const opt: PostConstructOption = {...defaultOption, ...option};
  // 返回Method装饰器
  return <MethodDecorator>function (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>): void {
    // 在方法上标记 PostConstruct Metadata
    Reflect.defineMetadata(Metadata_Key.postConstruct, opt, target, propertyKey);
  }
}

export {
  PostConstruct,
}
